﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQL_Provider;
using System.Data;
using System.Data.SqlClient;
using BusinessEntities;

namespace DataAccess
{
    public class TiepNhanBN_Adapter
    {
        Provider db;
        public TiepNhanBN_Adapter()
        {
            db = new Provider();
        }

        public DataTable TiepNhanBN_TrongNgay_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("TiepNhanBN_TrongNgay_All", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("TiepNhanBN_All", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("PhongKham_All", para, CommandType.StoredProcedure);
        }

        public DataTable DoiTuong_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("DoiTuong_All", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_HienTrang()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("PhongKham_HienTrang", para, CommandType.StoredProcedure);
        }

        public int TiepNhanBN_Them(TiepNhanBN_Info info)
        {
            SqlParameter[] para = new SqlParameter[12];
            para[0] = new SqlParameter("@MaBN", info.MaBN);
            para[1] = new SqlParameter("@PhongKham", info.PhongKham);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.TenBN);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            return db.Execute_Modify("TiepNhanBN_Them", para, CommandType.StoredProcedure);
        }

        public int TiepNhanBN_CapNhat(TiepNhanBN_Info info)
        {
            SqlParameter[] para = new SqlParameter[12];
            para[0] = new SqlParameter("@MaBN", info.MaBN);
            para[1] = new SqlParameter("@PhongKham", info.PhongKham);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.TenBN);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            return db.Execute_Modify("TiepNhanBN_CapNhat", para, CommandType.StoredProcedure);
        }

        public int PhongKhamBN_CapNhatSL(string PhongKham, int sl)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@PhongKham", PhongKham);
            para[1] = new SqlParameter("@SoBNCho", sl);
            return db.Execute_Modify("PhongKhamBN_CapNhatSL", para, CommandType.StoredProcedure);
        }

        public int TiepNhanBN_Xoa(int MaBN)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBN", MaBN);
            return db.Execute_Modify("TiepNhanBN_Xoa", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_TimTheoPhongKham(string PhongKham)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongKham", PhongKham);
            return db.Execute_Table("PhongKham_TimTheoPhongKham", para, CommandType.StoredProcedure);
        }

        public int TiepNhanBN_CapNhat_Kham(int MaBN, string Kham)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBN", MaBN);
            para[1] = new SqlParameter("@Kham", Kham);
            return db.Execute_Modify("TiepNhanBN_CapNhat_Kham", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_LayHanCuoiCung()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("TiepNhanBN_LayHanCuoiCung", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_TongBNCho()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("PhongKham_TongBNCho", para, CommandType.StoredProcedure);
        }

        //-------------------------------------------------------------------

        public DataTable TiepNhanBN_TimTheoMaBN(string MaBN)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBN", MaBN);
            return db.Execute_Table("TiepNhanBN_TimTheoMaBN", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimDanToc(string DanToc)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@DanToc", DanToc);
            return db.Execute_Table("TiepNhanBN_TimDanToc", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimDoiTuong(string DoiTuong)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@DoiTuong", DoiTuong);
            return db.Execute_Table("TiepNhanBN_TimDoiTuong", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoDiaChi(string DiaChi)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@DiaChi", DiaChi);
            return db.Execute_Table("TiepNhanBN_TimTheoDiaChi", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoHoTenBN(string HoTenBN)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@HoTenBN", HoTenBN);
            return db.Execute_Table("TiepNhanBN_TimTheoHoTenBN", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoNamNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("TiepNhanBN_TimTheoNamNhapVien", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoNgayNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("TiepNhanBN_TimTheoNgayNhapVien", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoNhomTuoi(int t1, int t2)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@t1", t1);
            para[1] = new SqlParameter("@t2", t2);
            return db.Execute_Table("TiepNhanBN_TimTheoNhomTuoi", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoPhongKham(string PhongKham)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongKham", PhongKham);
            return db.Execute_Table("TiepNhanBN_TimTheoPhongKham", para, CommandType.StoredProcedure);
        }

        public DataTable TiepNhanBN_TimTheoThangNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("TiepNhanBN_TimTheoThangNhapVien", para, CommandType.StoredProcedure);
        }
    }
}
